#include<stdio.h>
#include<math.h>
#include <stdlib.h>

double totalscore(double Lab, double Coursework, double MidE, double FinalE);
char Getgrade (double s);

int main (){
	
	FILE *scores, *result;
	int ID;
	char grade;
	double Lab , Coursework, MidE, FinalE, s; //s = total score//
	
	scores = fopen ("scores.txt", "r");
	if (scores == NULL){
		printf("Error: Failed to open scores.txt\n");
      exit(1);
	}
	result = fopen ("result.txt", "w");
	fprintf(result, "ID       SCORE   GRADE\n");
	while(fscanf(scores, "%d %lf %lf %lf %lf", &ID, &Lab, &Coursework, &MidE, &FinalE) != EOF){
	
			s = totalscore (Lab, Coursework, MidE, FinalE);
		grade = Getgrade (s);
		fprintf(result, "%d\t%lf\t%c\n", ID, s, grade);
		
	
		
	}
	fclose(scores);
	fclose(result);
	return 0;
}

//++++++++++++//
double totalscore(double Lab, double Coursework, double MidE, double FinalE){
	double s;
s =   Coursework*0.15 +	MidE *0.3 + FinalE *0.35+Lab*0.2;

return s;
}
//+++++++++++//
char Getgrade (double s){
	char grade;
	if(s>=85)
		grade = 'A';
	else if(s>=70 )
		grade = 'B';
	else if(s>=60 )
		grade = 'C';
	else if (s>=40 )
		grade = 'D';
	else 	
		grade = 'F';
	return grade;
}
